// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

module.exports = {
    sendSMS(tel, code){
        const SmsClient = tencentcloud.sms.v20210111.Client;
        const clientConfig = {
        credential: {
            secretId: "AKID5oLbaPUAzKWYSCrZJyYvW0GOsChLi8LZ",
            secretKey: "KgeNq2MPziBdopgV9PVRQtBd2iRya6MT",
        },
        region: "ap-nanjing",
        profile: {
            httpProfile: {
                endpoint: "sms.tencentcloudapi.com",
                },
            },
        };
        const client = new SmsClient(clientConfig);
        const params = {
            "PhoneNumberSet": [
                "+86" + tel
            ],
            "SmsSdkAppId": "1400489828",
            "SignName": "爱code爱生活",
            "TemplateId": "881527",
            "TemplateParamSet": [
                ""+code
            ]
        };
        return client.SendSms(params);
    },
    randomnumber(n){
        let str = "";
        for(let i=0;i<n;i++){
            str += Math.round(Math.random()*9)
        }
        return str;
    }
}